//
//  WelcomeView.swift
//  个人微博
//
//  Created by guo3920591 on 16/4/21.
//  Copyright © 2016年 guo3920591. All rights reserved.
//

import UIKit
import SDWebImage
/// 欢迎界面
class WelcomeView: UIView {

    override   init(frame: CGRect) {
        super.init(frame: UIScreen.mainScreen().bounds)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
 /// 视图生命周期
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        //更新约束
        iconImage.snp_updateConstraints { (make) -> Void in
            
            make.centerY.equalTo(self).offset(-100)
        }
        
        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 9.8, options: [], animations: { () -> Void in
             self.layoutIfNeeded()
            }) { (_) -> Void in
                
                self.removeFromSuperview()
               
        }
        
        
        
    }
    
    
// MARK: - 私有控件
    /// 头像视图
    private lazy var iconImage = UIImageView(imageName: "avatar_default_big")
    /// 欢迎标签
    private lazy var textlb = UILabel(text: "欢迎归来", fontsize: 16 )

}
// MARK: - 设置界面UI
extension WelcomeView{
    
    private func setupUI(){
       //设置背景
        backgroundColor = UIColor(patternImage: UIImage(named: "ad_background")!)
        //添加控件
        
        addSubview(iconImage)
        addSubview(textlb)
        
        let iconWH: CGFloat = 45
        
        iconImage.layer.cornerRadius = iconWH
        iconImage.layer.masksToBounds = true
        
        //自动布局
        
        iconImage.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(100)
            make.size.equalTo(CGSize(width: 2*iconWH, height: 2*iconWH))
            
            
        }
        
        textlb.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImage)
            make.top.equalTo(iconImage.snp_bottom).offset(15)
            
        }
        
        //强制布局
        
        layoutIfNeeded()
        
        //设置头像
        
       iconImage.xl_setImageUrl(OAuthModel.shareUserAccount.avatar_large, placeHoder: "avatar_default_big")
        
        
        
    }
    
    
    
}
